package com.my.springbootfile.controller;

import com.my.springbootfile.service.FileService;
import com.my.springbootfile.vo.ZipFileInVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpServletResponse;

/**
 * @author: marshal
 * @date: 2021-09-27 9:50 AM
 */
@RestController
@AllArgsConstructor
@RequestMapping("/file")
public class FileController {

    private final FileService fileService;

    /**
     *  测试，在postman输入以下参数，点击右侧的send and download
     *  {
     *     "filenames": ["1.txt", "a.md", "test.c"],
     *     "zipFilename": "test.zip"
     * }
     *
     * @param inVO
     */
    @PostMapping("/zipFileDownload")
    public void zipFileDownload(@RequestBody ZipFileInVO inVO) {
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        fileService.zipFileDownload(response, inVO);
    }

}
